<template>
  <div>
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="searchForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <Form-item prop="formName" :label="'表单名称:'">
          <Input
            type="text"
            v-model.trim="searchForm.formName"
            :placeholder="'请输入'"
            @on-enter="searchValueSet"
          ></Input>
        </Form-item>
        <Form-item prop="title" :label="'标题:'">
          <Input type="text" v-model.trim="searchForm.title" :placeholder="'请输入'" @on-enter="searchValueSet"></Input>
        </Form-item>
        <Form-item prop="formSubType" :label="'类型:'">
          <Input
            type="text"
            v-model.trim="searchForm.formSubType"
            :placeholder="'请输入'"
            @on-enter="searchValueSet"
          ></Input>
        </Form-item>
        <Form-item prop="org" :label="'单位:'">
          <Select v-model="searchForm.org" clearable @on-change="searchValueSet">
            <Option v-for="item in selectOrgData" :value="item.orgCode" :key="item.orgCode">{{ item.orgName }}</Option>
          </Select>
        </Form-item>
        <!-- 查询\重置按钮 -->
        <Form-item prop="button" class="search-solt-btn">
          <RPButton optType="search" ref="search" @click="searchValueSet" />
          <RPButton btnType="default" text="重置" @click="handleReset" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="valueSetTable" :config="pageTableConfig"> </InnerPageTable>
  </div>
</template>

<script>
import { selectColumns } from '../columns'
import { formType } from '@/views/formConst'
import dataApi from '@/api/formData'
export default {
  data() {
    return {
      selectOrgData: [],
      loading: true,
      searchForm: {
        org: '',
        formSubType: '',
        title: '',
        formName: ''
      },
      formTypeList: formType.filter(item => item.noOnline == false),
      pageTableConfig: {
        loadDataFn: this.getServiceList.bind(this),
        columns: selectColumns.bind(this)(),
        pageSize: 50,
        autoFirst: true //默认 就是 false, 要配置在这里
      }
    }
  },
  props: {
    bpmpId: {
      type: String,
      default: ''
    },
    orgDatas: { type: Array, default: () => [] }
  },
  computed: {},
  methods: {
    searchValueSet() {
      this.$refs['valueSetTable'].load(this.searchForm)
    },
    handleReset() {
      this.$refs['searchForm'].resetFields()
      this.searchValueSet()
    },
    getServiceList(tableObj) {
      let { responseProcess, param } = tableObj
      dataApi
        .scorePage({
          ...param,
          ...this.searchForm,
          currentPage: param.commonPageDTO.currentPage
        })
        .then(res => {
          let { size, total, current, records, pages } = res.data.data
          responseProcess({
            pageNum: current,
            pageSize: size,
            pages: pages,
            records: records || [],
            total: total
          })
        })
    },
    connectForm(row, title) {
      this.$confirm({
        title: title,
        content: `您是否要${title}当前表单?`
      }).then(res => {
        this.$emit('Close', { data: [row], title })
      })
    }
  },
  created() {
    this.orgDatas.forEach((item, index) => {
      this.selectOrgData.push(item)
      if (index == 0) {
        this.selectOrgData.splice(this.selectOrgData.length, 0, ...item.children)
      }
    })
    this.$emit('SetTitle', '选择被评分对象')
    this.$emit('SetPageWidth', 1000)
    this.$emit('SetPageActions', [
      {
        text: '确定',
        theme: 'primary',
        handle: () => {
          this.$emit('Close', this.$refs['valueSetTable'].selection)
        }
      },
      {
        text: '取消',
        handle: () => {
          this.$emit('Close')
        }
      }
    ])
  }
}
</script>

<style lang="scss" scoped></style>
